package com.unis.utils

import java.sql.{Connection, DriverManager}
import org.slf4j.{Logger, LoggerFactory}


object PhoenixUtil {
  var connection:Connection=_
  private val logger: Logger = LoggerFactory.getLogger(getClass)
  def getConnectoin():Connection={
    if(connection==null){
      val connection = DriverManager.getConnection("jdbc:phoenix:192.168.1.26:2181")
      connection
    }else{
      connection
    }
  }
  //保存数据到phoenix
  def SaveToPhoenix(sql: String, data: List[String]): Int = {
    var result: Int = 0
    lazy val con = getConnectoin()
    val stm = con.prepareStatement(sql)
    for(x<-0 to data.size-1){
      stm.setObject(x+1,data(x))
    }
    stm.executeUpdate()
    con.commit()
    result
  }

}
